package org.xp.judgeplatform.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.xp.judgeplatform.pojo.entity.ProblemSetMember;
import org.xp.judgeplatform.pojo.vo.ProblemSetVO.ProblemSetMemberVO;

@Mapper
public interface ProblemSetMemberMapper extends BaseMapper<ProblemSetMember> {

    /**
     * 分页查询题目集成员列表（包含用户信息）
     */
    @Select("SELECT m.*, u.username as user_name, u.avatar as user_avatar, u.email as user_email " +
            "FROM problem_set_members m " +
            "LEFT JOIN user u ON m.user_id = u.id " +
            "WHERE m.set_id = #{setId} " +
            "ORDER BY m.role DESC, m.joined_at ASC")
    IPage<ProblemSetMemberVO> selectMembersWithUserInfo(IPage<ProblemSetMemberVO> page,
                                                        @Param("setId") Long setId);
}
